<template>
  <transition name="el-zoom-in-center">
    <div class="cu-preview-main">
      <div class="cu-common-page-header">
        <el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'" />
        <div class="options">
          <el-button type="primary" @click="dataFormSubmit()" :loading="loading" v-if="!isDetail">确 定</el-button>
          <el-button @click="goBack">取 消</el-button>
        </div>
      </div>
      <el-row :gutter="15" class="main" :style="{ margin: '0 auto', width: '100%' }">
        <el-form ref="elForm" :model="dataForm" label-width="110px" label-position="right" :disabled="!!isDetail" :rules="rules">
          <el-col :span="8" v-if="custom.hasFormP('enCode') && isDetail">
            <el-form-item label="校区编码" prop="enCode">
              <el-input v-model="dataForm.enCode" :placeholder="isDetail ? '' : '请输入校区编码'" clearable required :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('fullName')">
            <el-form-item label="校区全称" prop="fullName">
              <el-input v-model="dataForm.fullName" :placeholder="isDetail ? '' : '请输入校区全称'" clearable required :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('shortName')">
            <el-form-item label="校区简称" prop="shortName">
              <el-input v-model="dataForm.shortName" :placeholder="isDetail ? '' : '请输入校区简称'" clearable required :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('openDate')">
            <el-form-item label="开业日期" prop="openDate">
              <el-date-picker v-model="dataForm.openDate" :placeholder="isDetail ? '' : '请选择开业日期'" clearable :style="{ width: '100%' }" type="date" format="yyyy-MM-dd" value-format="timestamp"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('telephone')">
            <el-form-item label="固定电话" prop="telephone">
              <el-input v-model="dataForm.telephone" :placeholder="isDetail ? '' : '请输入固定电话'" clearable :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('email')">
            <el-form-item label="校区邮箱" prop="email">
              <el-input v-model="dataForm.email" :placeholder="isDetail ? '' : '请输入校区邮箱'" clearable :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('manager')">
            <el-form-item label="校区负责人" prop="manager">
              <el-input v-model="dataForm.manager" :placeholder="isDetail ? '' : '请输入校区负责人'" clearable required :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('managerMobile')">
            <el-form-item label="负责人电话" prop="managerMobile">
              <el-input v-model="dataForm.managerMobile" :placeholder="isDetail ? '' : '请输入负责人电话'" clearable required :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('wechat')">
            <el-form-item label="负责人微信" prop="wechat">
              <el-input v-model="dataForm.wechat" :placeholder="isDetail ? '' : '请输入负责人微信'" clearable :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8" v-if="custom.hasFormP('startDate')">
            <el-form-item label="服务开始日期" prop="startDate">
              <el-date-picker v-model="dataForm.startDate" :style="{ width: '100%' }" type="date" format="yyyy-MM-dd" value-format="timestamp" :picker-options="pickerOptionsStart2"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('endDate')">
            <el-form-item label="服务截止日期" prop="endDate">
              <el-date-picker v-model="dataForm.endDate" :style="{ width: '100%' }" type="date" format="yyyy-MM-dd" value-format="timestamp" :picker-options="pickerOptionsEnd2"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('businessName')">
            <el-form-item label="营业执照主体" prop="businessName">
              <el-input v-model="dataForm.businessName" :placeholder="isDetail ? '' : '请输入营业执照主体'" clearable :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('area')">
            <el-form-item label="行政区域" prop="area">
              <custom-address v-model="dataForm.area" :placeholder="isDetail ? '' : '请选择行政区域'" clearable required></custom-address>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('address')">
            <el-form-item label="详细地址" prop="address">
              <el-input v-model="dataForm.address" :placeholder="isDetail ? '' : '请输入详细地址'" clearable required :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('type')">
            <el-form-item label="校区类型" prop="type">
              <el-select v-model="dataForm.type" :placeholder="isDetail ? '' : '请输入详细地址'" clearable required filterable :style="{ width: '100%' }">
                <el-option v-for="(item, index) in typeOptions" :key="index" :label="item.fullName" :value="item.enCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('schoolSituation')">
            <el-form-item label="学校规模" prop="schoolSituation">
              <el-input v-model="dataForm.schoolSituation" :placeholder="isDetail ? '' : '请输入小学/中学规模'" clearable :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('degreeCount')">
            <el-form-item label="学位数" prop="degreeCount">
              <el-input v-model="dataForm.degreeCount" :placeholder="isDetail ? '' : '请输入学位数'" clearable :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('bedCount')">
            <el-form-item label="床位数" prop="bedCount">
              <el-input v-model="dataForm.bedCount" :placeholder="isDetail ? '' : '请输入床位数'" clearable :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="custom.hasFormP('siteArea')">
            <el-form-item label="场地面积" prop="siteArea">
              <el-input v-model="dataForm.siteArea" :placeholder="isDetail ? '' : '请输入场地面积'" clearable :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="custom.hasFormP('site')">
            <el-form-item label="场地情况" prop="site">
              <el-input v-model="dataForm.site" placeholder="请输入" show-word-limit :style="{ width: '100%' }" type="textarea" :autosize="{ minRows: 4, maxRows: 4 }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="custom.hasFormP('personnel')">
            <el-form-item label="人员情况" prop="personnel">
              <el-input v-model="dataForm.personnel" placeholder="请输入" show-word-limit :style="{ width: '100%' }" type="textarea" :autosize="{ minRows: 4, maxRows: 4 }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="custom.hasFormP('description')">
            <el-form-item label="备注" prop="description">
              <el-input v-model="dataForm.description" placeholder="请输入" show-word-limit :style="{ width: '100%' }" type="textarea" :autosize="{ minRows: 4, maxRows: 4 }"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="isDetail">
            <el-tabs type="border-card" tab-position="top" v-model="active1" class="mb-10">
              <el-tab-pane label="校区合同" v-if="custom.hasFormP('contractList')">
                <el-col :span="24">
                  <el-form-item label-width="0">
                    <custom-table v-loading="loading" :data="dataForm.contractList">
                      <el-table-column prop="type" label="类型" align="center" width="80">
                        <template slot-scope="scope">
                          {{ scope.row.type | dynamicCodeText(contractTypeOptions) }}
                        </template>
                      </el-table-column>
                      <el-table-column prop="startDate" label="开始日期" align="center" :formatter="custom.tableDateFormat" width="100" />
                      <el-table-column prop="endDate" label="截止日期" align="center" :formatter="custom.tableDateFormat" width="100" />
                      <el-table-column prop="receivable" label="应收金额" align="right" width="80" />
                      <el-table-column prop="actual" label="实收金额" align="right" width="80" />
                      <el-table-column prop="isPayed" label="支付情况" align="center" width="80">
                        <template slot-scope="scope">
                          {{ scope.row.isPayed | dynamicCodeText(payStatusOptions) }}
                        </template>
                      </el-table-column>
                      <el-table-column prop="policy" label="政策" align="left" />
                      <el-table-column prop="fileNo" label="档案编码" align="left" />
                      <el-table-column prop="createUserName" label="创建用户" align="left" width="80" />
                      <el-table-column prop="createTime" label="创建时间" align="center" :formatter="custom.tableDateTimeFormat" width="120" />
                    </custom-table>
                  </el-form-item>
                </el-col>
              </el-tab-pane>
              <el-tab-pane label="投资人信息" v-if="custom.hasFormP('contactList')">
                <el-col :span="24">
                  <el-form-item label-width="0">
                    <custom-table v-loading="loading" :data="dataForm.contactList">
                      <el-table-column prop="isSigner" label="是否签约人" align="center" width="100">
                        <template slot-scope="scope" v-if="scope.row.isSigner">
                          <el-checkbox v-model="scope.row.isSigner"></el-checkbox>
                        </template>
                      </el-table-column>
                      <el-table-column prop="name" label="姓名" width="80" header-align="center" />
                      <el-table-column prop="signingType" label="签约类型" align="center" width="100">
                        <template slot-scope="scope">
                          {{ scope.row.signingType | dynamicCodeText(signingTypeOptions) }}
                        </template>
                      </el-table-column>
                      <el-table-column prop="gender" label="性别" width="80" align="center">
                        <template slot-scope="scope">
                          {{ scope.row.gender | dynamicCodeText(genderOptions) }}
                        </template>
                      </el-table-column>
                      <el-table-column prop="mobile" label="联系电话" align="center" width="100" />
                      <el-table-column prop="idNumber" label="证件号码" align="center" width="150" />
                      <el-table-column prop="wechat" label="微信" header-align="center" width="130" />
                      <el-table-column prop="email" label="邮箱" header-align="center" width="150" />
                      <!-- 企业信息字段 -->
                      <el-table-column prop="companyName" label="公司名称" align="center" width="150" v-if="dataForm.contactList && dataForm.contactList.some(item => item.signingType === 'company')">
                        <template slot-scope="scope">
                          <span v-if="scope.row.signingType === 'company'">{{ scope.row.companyName }}</span>
                          <span v-else>-</span>
                        </template>
                      </el-table-column>
                      <el-table-column prop="companyAddress" label="公司地址" align="center" width="200" v-if="dataForm.contactList && dataForm.contactList.some(item => item.signingType === 'company')">
                        <template slot-scope="scope">
                          <span v-if="scope.row.signingType === 'company'">{{ scope.row.companyAddress }}</span>
                          <span v-else>-</span>
                        </template>
                      </el-table-column>
                      <el-table-column prop="creditCode" label="信用代码" align="center" width="180" v-if="dataForm.contactList && dataForm.contactList.some(item => item.signingType === 'company')">
                        <template slot-scope="scope">
                          <span v-if="scope.row.signingType === 'company'">{{ scope.row.creditCode }}</span>
                          <span v-else>-</span>
                        </template>
                      </el-table-column>
                      <el-table-column prop="companyPhone" label="公司电话" align="center" width="120" v-if="dataForm.contactList && dataForm.contactList.some(item => item.signingType === 'company')">
                        <template slot-scope="scope">
                          <span v-if="scope.row.signingType === 'company'">{{ scope.row.companyPhone }}</span>
                          <span v-else>-</span>
                        </template>
                      </el-table-column>
                      <el-table-column prop="companyEmail" label="公司邮箱" align="center" width="150" v-if="dataForm.contactList && dataForm.contactList.some(item => item.signingType === 'company')">
                        <template slot-scope="scope">
                          <span v-if="scope.row.signingType === 'company'">{{ scope.row.companyEmail }}</span>
                          <span v-else>-</span>
                        </template>
                      </el-table-column>
                      <!-- 法人代表信息字段 -->
                      <el-table-column prop="legalRepName" label="法人代表" align="center" width="100" v-if="dataForm.contactList && dataForm.contactList.some(item => item.signingType === 'company')">
                        <template slot-scope="scope">
                          <span v-if="scope.row.signingType === 'company'">{{ scope.row.legalRepName }}</span>
                          <span v-else>-</span>
                        </template>
                      </el-table-column>
                      <el-table-column prop="legalRepIdNumber" label="法人身份证" align="center" width="150" v-if="dataForm.contactList && dataForm.contactList.some(item => item.signingType === 'company')">
                        <template slot-scope="scope">
                          <span v-if="scope.row.signingType === 'company'">{{ scope.row.legalRepIdNumber }}</span>
                          <span v-else>-</span>
                        </template>
                      </el-table-column>
                      <el-table-column prop="legalRepMobile" label="法人电话" align="center" width="120" v-if="dataForm.contactList && dataForm.contactList.some(item => item.signingType === 'company')">
                        <template slot-scope="scope">
                          <span v-if="scope.row.signingType === 'company'">{{ scope.row.legalRepMobile }}</span>
                          <span v-else>-</span>
                        </template>
                      </el-table-column>
                      <el-table-column prop="legalRepWechat" label="法人微信" align="center" width="120" v-if="dataForm.contactList && dataForm.contactList.some(item => item.signingType === 'company')">
                        <template slot-scope="scope">
                          <span v-if="scope.row.signingType === 'company'">{{ scope.row.legalRepWechat }}</span>
                          <span v-else>-</span>
                        </template>
                      </el-table-column>
                      <el-table-column prop="description" label="备注" />
                    </custom-table>
                  </el-form-item>
                </el-col>
              </el-tab-pane>
              <el-tab-pane label="双师帐号" v-if="custom.hasFormP('accountList')">
                <el-col :span="24">
                  <el-form-item label-width="0">
                    <custom-table v-loading="loading" :data="dataForm.accountList">
                      <el-table-column prop="goodsName" label="商品名称" align="left" width="200" show-overflow-tooltip></el-table-column>
                      <el-table-column prop="typeName" label="商品规格" width="160" />
                      <el-table-column prop="price" label="价格" align="right" width="60" />
                      <el-table-column prop="account" label="帐号" align="center" width="150" />
                      <el-table-column prop="openDate" label="开通日期" align="center" :formatter="custom.tableDateFormat" width="100" />
                      <el-table-column prop="startDate" label="开始日期" align="center" :formatter="custom.tableDateFormat" width="100" />
                      <el-table-column prop="endDate" label="截止日期" align="center" :formatter="custom.tableDateFormat" width="100" />
                      <el-table-column prop="status" label="帐号状态" align="center">
                        <template slot-scope="scope">
                          <span class="label label-success" style="cursor: pointer;" v-if="scope.row.status == 0">正常</span>
                          <span class="label label-success" style="cursor: pointer;" v-else-if="scope.row.status == 2">退款</span>
                          <span class="label label-success" style="cursor: pointer;" v-else-if="scope.row.status == 4">作废</span>
                          <span class="label label-success" style="cursor: pointer;" v-else>{{ scope.row.status }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column prop="source" label="帐号来源" align="center">
                        <template slot-scope="scope">
                          {{ scope.row.source | dynamicCodeText(sourceOptions) }}
                        </template>
                      </el-table-column>
                      <el-table-column prop="description" label="备注" align="left" width="200" show-overflow-tooltip />
                      <el-table-column prop="createTime" label="创建时间" align="center" :formatter="custom.tableDateTimeFormat" width="120" />
                      <el-table-column prop="createUserName" label="创建用户" align="left" />
                      <el-table-column prop="updateTime" label="修改时间" align="center" :formatter="custom.tableDateTimeFormat" width="120" />
                      <el-table-column prop="updateUserName" label="修改用户" align="left" />
                    </custom-table>
                  </el-form-item>
                </el-col>
              </el-tab-pane>
              <el-tab-pane label="保险记录" v-if="custom.hasFormP('insuranceList')">
                <el-col :span="24">
                  <el-form-item label-width="0">
                    <custom-table v-loading="loading" :data="list" :hasNO="false">
                      <el-table-column prop="policyName" label="保险名称" align="left">
                        <template slot-scope="scope">
                          {{ scope.row.policyName | dynamicCodeText(policyNameOptions) }}
                        </template>
                      </el-table-column>
                      <el-table-column prop="policyNumber" label="投保单号" align="center" />
                      <el-table-column prop="insuranceCompany" label="投保公司" align="left">
                        <template slot-scope="scope">
                          {{ scope.row.insuranceCompany | dynamicCodeText(insuranceCompanyOptions) }}
                        </template>
                      </el-table-column>
                      <el-table-column prop="effectiveDate" label="投保日期" align="center" :formatter="custom.tableDateFormat" />
                      <el-table-column prop="expirationDate" label="到期日期" align="center" :formatter="custom.tableDateFormat" />
                      <el-table-column prop="createUserName" label="记录人" align="left" />
                      <el-table-column prop="description" label="备注" width="200" show-overflow-tooltip />
                    </custom-table>
                  </el-form-item>
                </el-col>
              </el-tab-pane>
              <el-tab-pane label="参训信息" v-if="custom.hasFormP('trainingData')">
                <el-col :span="24">
                  <el-form-item label-width="0">
                    <div v-if="!dataForm.trainingData || dataForm.trainingData.length === 0" class="empty-data">
                      <i class="el-icon-info"></i>
                      <span>暂无参训数据</span>
                    </div>
                    <el-table v-else :data="dataForm.trainingData" v-loading="trainingDataLoading" style="width: 100%" border>
                      <el-table-column prop="trainTitle" label="师训名称"></el-table-column>
                      <el-table-column prop="teacherName" label="参训人员"></el-table-column>
                      <el-table-column prop="position" label="职务"></el-table-column>
                      <el-table-column prop="trainTime" label="参训时间" :formatter="custom.tableDateFormat"></el-table-column>
                      <el-table-column prop="isCompleted" label="是否结业">
                        <template slot-scope="scope">
                          <el-tag :type="scope.row.isCompleted ? 'success' : 'warning'">
                            {{ scope.row.isCompleted ? '已结业' : '未结业' }}
                          </el-tag>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-form-item>
                </el-col>
              </el-tab-pane>
              <el-tab-pane label="家校信息" v-if="custom.hasFormP('schoolInfo')">
                <el-col :span="24">
                  <el-form-item label-width="0">
                    <div class="data-grid border-title">
                      <div class="data-system-list">
                        <span>在职老师</span>
                        <span class="data-text">{{ dataForm.teacherCount || 0 }}人</span>
                      </div>
                      <div class="data-system-list">
                        <span>学生人数(家校系统)</span>
                        <span class="data-text">{{ dataForm.studentCount || 0 }}人</span>
                      </div>
                      <div class="data-system-list">
                        <span>学生人数(服务期)</span>
                        <span class="data-text">{{ dataForm.normalStudentNum || 0 }}人</span>
                      </div>
                      <div class="data-system-list">
                        <span>创建班级</span>
                        <span class="data-text">{{ dataForm.classCount || 0 }}个</span>
                      </div>
                    </div>
                  </el-form-item>
                </el-col>
              </el-tab-pane>
            </el-tabs>
          </el-col>
        </el-form>
      </el-row>
    </div>
  </transition>
</template>
<script>
import request from '@/utils/request'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import { getCampusTrainingData, getSchoolZoneEnrollments } from '@/api/campus/campus'
export default {
  components: {},
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      isDetail: false,
      list: [],
      trainingDataLoading: false,
      policyNameOptions: [
        {
          enCode: '1',
          fullName: '三合一'
        },
        {
          enCode: '2',
          fullName: '雇主责任险'
        },
        {
          enCode: '3',
          fullName: '公众责任险'
        },
        {
          enCode: '4',
          fullName: '财产一切险'
        },
        {
          enCode: '5',
          fullName: '公众责任险+雇主责任险'
        },
        {
          enCode: '6',
          fullName: '公众责任险+财产一切险'
        },
        {
          enCode: '7',
          fullName: '其他'
        }
      ],
      insuranceCompanyOptions: [
        {
          enCode: '1',
          fullName: '未办理'
        },
        {
          enCode: '2',
          fullName: '安亲保'
        },
        {
          enCode: '3',
          fullName: '放心保'
        },
        {
          enCode: '4',
          fullName: '平安保险'
        },
        {
          enCode: '5',
          fullName: '太平洋保险'
        },
        {
          enCode: '6',
          fullName: '中国人寿'
        },
        {
          enCode: '7',
          fullName: '阳光保险'
        },
        {
          enCode: '8',
          fullName: '其他'
        }
      ],
      dataForm: {
        id: '',
        enCode: undefined,
        fullName: undefined,
        shortName: undefined,
        openDate: undefined,
        telephone: undefined,
        email: undefined,
        manager: undefined,
        managerMobile: undefined,
        area: undefined,
        wechat: undefined,
        address: undefined,
        fullAddress: undefined,
        insurance: undefined,
        insuranceNo: undefined,
        insuranceDate: undefined,
        businessName: undefined,
        businessNo: undefined,
        siteArea: undefined,
        rent: undefined,
        usableArea: undefined,
        type: undefined,
        campusContractList: [],
        campusContactList: [],
        campusAccountList: [],
        endDate: undefined,
        startDate: undefined,
        createUserName: undefined,
        createTime: undefined,
        updateUserName: undefined,
        updateTime: undefined,
        description: undefined,
        personnel: undefined,
        schoolSituation: undefined,
        contract: undefined,
        cloudPlatform: undefined,
        franchise: undefined,
        renewal: undefined,
        deposit: undefined,
        coopMode: undefined,
        status: undefined,
        degreeCount: undefined,
        bedCount: undefined,
        // 参训信息相关数据
        trainingData: [],
        // 家校信息相关数据
        teacherCount: 0,
        studentCount: 0,
        normalStudentNum: 0,
        classCount: 0
      },
      // 开始结束日期限制
      pickerOptionsStart2: {
        disabledDate: time => {
          if (this.dataForm.endTime) {
            return time.getTime() >= new Date(this.dataForm.endTime).getTime()
          }
        }
      },
      // 结束日期限制
      pickerOptionsEnd2: {
        disabledDate: time => {
          if (this.dataForm.startDate) {
            return time.getTime() <= new Date(this.dataForm.startDate).getTime()
          }
        }
      },
      rules: {
        enCode: [
          {
            required: true,
            message: '请输入校区编码',
            trigger: 'blur'
          }
        ],
        fullName: [
          {
            required: true,
            message: '请输入校区全称',
            trigger: 'blur'
          }
        ],
        type: [
          {
            required: true,
            message: '请选择校区类型',
            trigger: 'change'
          }
        ],
        shortName: [
          {
            required: true,
            message: '请输入校区简称',
            trigger: 'blur'
          }
        ],
        email: [
          {
            pattern: /^[a-z0-9]+([._\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/,
            message: '请输入正确的邮箱',
            trigger: 'blur'
          }
        ],
        manager: [
          {
            required: true,
            message: '请输入校区负责人',
            trigger: 'blur'
          }
        ],
        managerMobile: [
          {
            required: true,
            message: '请输入负责人电话',
            trigger: 'blur'
          }
        ],
        area: [
          {
            required: true,
            message: '请选择行政区域',
            trigger: 'change'
          }
        ],
        address: [
          {
            required: true,
            message: '请输入详细地址',
            trigger: 'blur'
          }
        ]
      },
      typeOptions: [],
      contractTypeOptions: [],
      payStatusOptions: [],
      genderOptions: [],
      // identityOptions: [],
      signingTypeOptions: [],
      sourceOptions: [{ fullName: '订单', enCode: '1' }, { fullName: '赠送', enCode: '2' }],
      statusOptions: [{ fullName: '正常', enCode: '1' }, { fullName: '退款', enCode: '2' }, { fullName: '作废', enCode: '4' }],
      active1: '0'
    }
  },
  computed: {},
  watch: {},
  created() {
    this.$store.dispatch('base/getDictionaryData', { sort: 'CampusType' }).then(res => {
      this.typeOptions = res
    })
    this.$store.dispatch('base/getDictionaryData', { sort: 'SignType' }).then(res => {
      this.contractTypeOptions = res
    })
    this.$store.dispatch('base/getDictionaryData', { sort: 'CampusStatus' }).then(res => {
      this.statusOptions = res
    })
    this.$store.dispatch('base/getDictionaryData', { sort: 'PayStatus' }).then(res => {
      this.payStatusOptions = res
    })
    this.$store.dispatch('base/getDictionaryData', { sort: 'sex' }).then(res => {
      this.genderOptions = res
    })
    // 临时使用静态数据
    this.signingTypeOptions = [{ enCode: 'personal', fullName: '个人签约' }, { enCode: 'company', fullName: '企业签约' }]
  },
  mounted() {},
  methods: {
    getData() {
      this.list = []

      request({
        url: 'api/campus/insurance/records/' + this.campusId,
        method: 'get'
      }).then(res => {
        this.list = res.data
      })
    },
    goBack() {
      this.$emit('refresh')
    },
    init(id, isDetail) {
      this.campusId = id
      this.dataForm.id = id || ''
      this.visible = true
      this.isDetail = isDetail || false
      this.$nextTick(() => {
        this.$refs['elForm'].resetFields()
        if (this.dataForm.id) {
          this.getData()
          request({
            url: `api/campus/${this.dataForm.id}/info`,
            method: 'get'
          }).then(res => {
            this.dataForm = res.data
            console.log(this.dataForm)
            // 加载参训数据和家校信息
            this.loadTrainingData()
            this.loadSchoolInfo()
          })
        }
      })
    },
    dataFormSubmit() {
      this.$refs['elForm'].validate(valid => {
        if (valid) {
          this.loading = true
          if (!this.dataForm.id) {
            request({
              url: `api/campus`,
              method: 'post',
              data: this.dataForm
            })
              .then(res => {
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                    this.visible = false
                    this.loading = false
                    this.$emit('refresh', true)
                  }
                })
              })
              .catch(res => {
                console.log(res)
                this.loading = false
              })
          } else {
            request({
              url: 'api/campus/' + this.dataForm.id,
              method: 'PUT',
              data: this.dataForm
            })
              .then(res => {
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                    this.visible = false
                    this.loading = false
                    this.$emit('refresh', true)
                  }
                })
              })
              .catch(res => {
                console.log(res)
                this.loading = false
              })
          }
        }
      })
    },
    // 加载参训数据
    loadTrainingData() {
      if (!this.dataForm.id) return

      this.trainingDataLoading = true
      getCampusTrainingData(this.dataForm.id)
        .then(res => {
          this.dataForm.trainingData = res.data || []
        })
        .catch(err => {
          console.error('加载参训数据失败:', err)
          this.dataForm.trainingData = []
        })
        .finally(() => {
          this.trainingDataLoading = false
        })
    },
    // 加载家校信息数据
    loadSchoolInfo() {
      if (!this.dataForm.id) return

      getSchoolZoneEnrollments(this.dataForm.id)
        .then(res => {
          const data = res.data || {}
          this.dataForm.teacherCount = data.teacherNum || 0
          this.dataForm.studentCount = data.studentNum || 0
          this.dataForm.classCount = data.classNum || 0
          this.dataForm.normalStudentNum = data.normalStudentNum || 0
        })
        .catch(err => {
          console.error('加载家校信息失败:', err)
          this.dataForm.teacherCount = 0
          this.dataForm.studentCount = 0
          this.dataForm.classCount = 0
          this.dataForm.normalStudentNum = 0
        })
    }
  }
}
</script>

<style lang="scss" scoped>
/* 空数据状态样式 */
.empty-data {
  text-align: center;
  padding: 40px 0;
  color: #909399;
  font-size: 14px;

  i {
    font-size: 24px;
    margin-bottom: 10px;
    display: block;
  }
}

/* 家校信息数据网格样式 */
.data-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 20px;
  background-color: #f8f9fa;
  border-radius: 6px;

  &.border-title {
    border: 1px solid #e4e7ed;
  }
}

.data-system-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 120px;
  padding: 15px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

  span:first-child {
    font-size: 14px;
    color: #606266;
    margin-bottom: 8px;
  }

  .data-text {
    font-size: 18px;
    font-weight: bold;
    color: #409eff;
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .data-grid {
    flex-direction: column;
    gap: 10px;
  }

  .data-system-list {
    min-width: auto;
    width: 100%;
  }
}
</style>
